#include <scott/Command.h>

BOOST_AUTO_TEST_SUITE( Command_Test_Suite )

//  [ byte, char, number, string ] = SimpleCommand( byte, char, number, string)

BOOST_AUTO_TEST_CASE( Command_Create_Test )
{
	// Creazione del CommandDescriptor
	CommandDescriptorSp cd = 
		CommandDescriptor::Create("math", "somma", "Somma due numeri.");

	cd->AddInputParameter("a", "Primo addendo", STypeNumber);
	cd->AddInputParameter("b", "Secondo addendo", STypeNumber);

	cd->AddOutputParameter("ris", "Risultato della somma", STypeNumber);

	// Creazione del comando
	CommandSp cmd = Command::Create(cd, "a = 10, b = 20");

	// Prelevo i parametri di input del comando
	SStructSp inputs = cmd->GetInputs();

	unsigned long a = inputs->Get<SNumber>("a")->Get();
	unsigned long b = inputs->Get<SNumber>("b")->Get();

	// Imposto il risultato del comando
	SStructSp outputs = cmd->GetOutputs();

	outputs->Set("ris", SNumber::Create( a + b ) );

	//// Data
	//CommandDescriptorSp cd = CommandDescriptor::Create("plugin", "SimpleCommand", "SimpleCommand description");

	//cd->AddInputParameter("B", "A SByte", STypeByte);
	//cd->AddInputParameter("C", "A SChar", STypeChar);
	//cd->AddInputParameter("Num", "A SNumber", STypeNumber);
	//cd->AddInputParameter("Str", "A String", STypeString);

	//cd->AddOutputParameter("B", "A SByte", STypeByte);
	//cd->AddOutputParameter("C", "A SChar", STypeChar);
	//cd->AddOutputParameter("Num", "A SNumber", STypeNumber);
	//cd->AddOutputParameter("Str", "A String", STypeString);

	//// Parameters
	//string commandArgs = " 10, 'A', 1234, \"Hello\" ";

	//// Test input
	//CommandSp cmd = Command::Create(cd, commandArgs);

 //	BOOST_CHECK( cmd->GetCommandDescriptor() == cd );

	//SStructSp inputs = cmd->GetInputs();

	//BOOST_CHECK( inputs->Get<SByte>(0)->Get() == 10 );
	//BOOST_CHECK( inputs->Get<SChar>(1)->Get() == 'A' );
	//BOOST_CHECK( inputs->Get<SNumber>(2)->Get() == 1234 );
	//BOOST_CHECK( inputs->Get<SString>(3)->Get() == "Hello" );

	//BOOST_CHECK( inputs->Get<SByte>("B")->Get() == 10 );
	//BOOST_CHECK( inputs->Get<SChar>("C")->Get() == 'A' );
	//BOOST_CHECK( inputs->Get<SNumber>("Num")->Get() == 1234 );
	//BOOST_CHECK( inputs->Get<SString>("Str")->Get() == "Hello" );

	//// Test outputs
	//SStructSp outputs = cmd->GetOutputs();
	//outputs->Set("B", SByte::Create(1) );
	//outputs->Set("C", SChar::Create('z') );
	//outputs->Set("Num", SNumber::Create(12) );
	//outputs->Set("Str", SString::Create("Hi") );

	//BOOST_CHECK( cmd->GetOutputs()->Get<SByte>("B")->Get() == 1 );
	//BOOST_CHECK( cmd->GetOutputs()->Get<SChar>("C")->Get() == 'z' );
	//BOOST_CHECK( cmd->GetOutputs()->Get<SNumber>("Num")->Get() == 12 );
	//BOOST_CHECK( cmd->GetOutputs()->Get<SString>("Str")->Get() == "Hi" );
}

BOOST_AUTO_TEST_CASE( Command_Create2_Test )
{
	// Data
	CommandDescriptorSp cd = CommandDescriptor::Create("plugin", "Command2", "Command2 description");

	SEnumTypeDescriptorSp etd = SEnumTypeDescriptor::Create("plugin", "colors", "");
	etd->AddEntry("red", 0, "red color");
	etd->AddEntry("yellow", 1, "yellow color");
	etd->AddEntry("green", 2, "green color");
	
	cd->AddInputParameter("Enum", "A enum", etd);

	cd->AddOutputParameter("Enum", "A enum", etd);

	// Test
	CommandSp cmd = Command::Create(cd, "yellow");

 	BOOST_CHECK( cmd->GetCommandDescriptor() == cd );

	SStructSp inputs = cmd->GetInputs();

	BOOST_CHECK( inputs->Get<SEnum>(0)->Get() == "yellow" );
	BOOST_CHECK( inputs->Get<SEnum>("Enum")->Get() == "yellow" );

	// Test outputs
	SStructSp outputs = cmd->GetOutputs();
	SEnumTypeDescriptorSp td = cmd->GetOutputTypeDescriptor<SEnumTypeDescriptor>(0);

	outputs->Set("Enum", SEnum::Create( td, "yellow") );

	//cmd->GetOutput<SByte>("Enum")

	BOOST_CHECK( cmd->GetOutputs()->Get<SEnum>("Enum")->Get() == "yellow" );
}

BOOST_AUTO_TEST_SUITE_END()
